import java.util.Arrays;

public class LeetCode1137 {

    public static void main(String[] args) {
        System.out.println(tribonacci(25));
    }

    private static final int[] START = {0, 1, 1};

    public static int tribonacci(int n) {
        if (n < 3) {
            return START[n];
        }

        int n1 = START[0];
        int n2 = START[1];
        int n3 = START[2];

        while (n >= 3) {
            n3 = n3 + n2 + n1;
            int c = n2;
            n2 = n3 - n2 - n1;
            n1 = c;

            n--;
        }

        return n3;
    }
}
